package com.handpay.zztong.hp.notification.model;

import com.handpay.framework.fastjson.FastJsonHelper;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.base.callback.BusinessEngineListener;
import com.handpay.zztong.hp.base.model.base.BaseModel;
import com.handpay.zztong.hp.config.HttpUrlConstant;
import com.handpay.zztong.hp.notification.bean.UserNoticesBean;

import java.util.Hashtable;

/**
 * @author sxshi on 2017/5/2.
 *         email:emotiona_xiaoshi@126.com
 *         describe:Describe the function  of the current class
 */

public class NoticeModel extends BaseModel {
    private ZZTongActivity mContext;
    private BusinessEngineListener<UserNoticesBean> mBusinessEngineListener;

    public NoticeModel(ZZTongActivity context) {
        this.mContext = context;
    }

    /**
     * get notices
     *
     * @param action                 request action
     * @param paramers               request paramers
     * @param businessEngineListener callback listener
     */
    public void getNotices(String action, Hashtable<String, String> paramers, BusinessEngineListener<UserNoticesBean> businessEngineListener) {
        this.mBusinessEngineListener = businessEngineListener;
        doPost(mContext, action, paramers,false);
    }

    @Override
    public boolean netResponse(String action, byte[] data) {
        if (super.netResponse(action, data)) {
            return true;
        }
        if (action.equals(HttpUrlConstant.Do_GetUserNotices)) {
            UserNoticesBean userNoticesBean = new UserNoticesBean();
            if (data_type == DATA_TYPE.DATA_TYPE_JSON) {
                userNoticesBean = FastJsonHelper.getObject(new String(data), UserNoticesBean.class);
            }
            if (mBusinessEngineListener != null) mBusinessEngineListener.callbackBusinessResponse(userNoticesBean);
        }
        return true;
    }
}
